package com.example.night.controller;

import com.example.night.service.ApiService.yuantuitui.LoginService;
import org.springframework.web.bind.annotation.*;
import org.springframework.http.ResponseEntity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@RestController
@RequestMapping("/api/login")
public class TYYLoginController {

    private static final Logger logger = LoggerFactory.getLogger(TYYLoginController.class);

    private final LoginService loginService;

    public TYYLoginController(LoginService loginService) {
        this.loginService = loginService;
    }

    @PostMapping("/login")
    public ResponseEntity<String> recCode(
            @RequestParam String mobile,  // 接收手机号参数
            @RequestParam String code) {  // 接收验证码参数
        try {
            logger.info("收到登录请求，手机号: {}, Code: {}", mobile, code);

            // 设置手机号和验证码
            loginService.setCode(mobile, code);

            return ResponseEntity.ok("手机号和验证码已接收，手机号: " + mobile + ", Code: " + code);
        } catch (Exception e) {
            logger.error("处理登录请求时发生异常: ", e);
            return ResponseEntity.status(500).body("登录失败: " + e.getMessage());
        }
    }
}
